import fetch from 'node-fetch'
// @ts-ignore
import loverWordsArr from '../data/lover_words.json'
import _ from 'lodash'
import store from '../store/store'

export default async function say_love() {
    if (store.love_words) {
        return store.love_words
    }
    let words = '哼，你知道的'
    try {
        let resp = await fetch('https://api.mcloc.cn/love/')
        words = await resp.text()
    } catch (e) {
        let randomIndex = _.random(0, loverWordsArr.length - 1)
        words = loverWordsArr[randomIndex]
        console.error('get random lover message err:', e)
    } finally {
        store.love_words = words
        return words
    }
}